<?php
error_reporting(E_ALL);
date_default_timezone_set('Asia/Shanghai');
require_once '../../lib/phpexcel/PHPExcel.php';
require_once '../../lib/phpexcel/PHPExcel/Writer/Excel2007.php';

/**
 * The control file of report module of ZenTaoPMS.
 *
 * @copyright   Copyright 2009-2015 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
 * @license     ZPL (http://zpl.pub/page/zplv12.html)
 * @author      Chunsheng Wang <chunsheng@cnezsoft.com>
 * @package     report
 * @version     $Id: control.php 4622 2013-03-28 01:09:02Z chencongzhi520@gmail.com $
 * @link        http://www.zentao.net
 */
class report extends control
{
    /**
     * The index of report, goto project deviation.
     *
     * @access public
     * @return void
     */
    public function index()
    {
        $this->locate(inlink('productSummary'));
    }

    /**
     * Project deviation report.
     *
     * @access public
     * @return void
     */
    public function projectDeviation($begin = 0, $end = 0)
    {
        $begin = $begin ? date('Y-m-d', strtotime($begin)) : '';
        $end = $end ? date('Y-m-d', strtotime($end)) : '';

        $this->view->title = $this->lang->report->projectDeviation;
        $this->view->position[] = $this->lang->report->projectDeviation;

        $this->view->projects = $this->report->getProjects($begin, $end);
        $this->view->begin = $begin;
        $this->view->end = $end;
        $this->view->submenu = 'project';
        $this->display();
    }

    /**
     * Product information report.
     *
     * @access public
     * @return void
     */
    public function productSummary($conditions = '')
    {
        $this->app->loadLang('product');
        $this->app->loadLang('productplan');
        $this->app->loadLang('story');
        $this->view->title = $this->lang->report->productSummary;
        $this->view->position[] = $this->lang->report->productSummary;
        $this->view->products = $this->report->getProducts($conditions);
        $this->view->users = $this->loadModel('user')->getPairs('noletter|noclosed');
        $this->view->submenu = 'product';
        $this->view->conditions = $conditions;
        $this->display();
    }

    /**
     * Bug create report.
     *
     * @param int $begin
     * @param int $end
     * @access public
     * @return void
     */
    public function bugCreate($begin = 0, $end = 0, $product = 0, $project = 0)
    {
        $this->app->loadLang('bug');
        $begin = $begin == 0 ? date('Y-m-d', strtotime('last month', strtotime(date('Y-m', time()) . '-01 00:00:01'))) : date('Y-m-d', strtotime($begin));
        $end = $end == 0 ? date('Y-m-d', strtotime('now')) : $end = date('Y-m-d', strtotime($end));

        $this->view->title = $this->lang->report->bugCreate;
        $this->view->position[] = $this->lang->report->bugCreate;
        $this->view->begin = $begin;
        $this->view->end = $end;
        $this->view->bugs = $this->report->getBugs($begin, $end, $product, $project);
        $this->view->users = $this->loadModel('user')->getPairs('noletter|noclosed|nodeleted');
        $this->view->projects = array('' => '') + $this->loadModel('project')->getPairs();
        $this->view->products = array('' => '') + $this->loadModel('product')->getPairs();
        $this->view->project = $project;
        $this->view->product = $product;
        $this->view->submenu = 'test';
        $this->display();
    }

    /**
     * Bug assign report.
     *
     * @access public
     * @return void
     */
    public function bugAssign()
    {
        $this->view->title = $this->lang->report->bugAssign;
        $this->view->position[] = $this->lang->report->bugAssign;
        $this->view->submenu = 'test';
        $this->view->assigns = $this->report->getBugAssign();
        $this->view->users = $this->loadModel('user')->getPairs('noletter|noclosed|nodeleted');
        $this->display();
    }

    /**
     * Workload report.
     *
     * @param string $begin
     * @param string $end
     * @param int $days
     * @param int $workday
     * @param int $dept
     * @param int $assign
     *
     * @access public
     * @return void
     */
    public function workload($begin = '', $end = '', $days = 0, $workday = 0, $dept = 0, $assign = 'assign')
    {
        if ($_POST) {
            $data = fixer::input('post')->get();
            $begin = $data->begin;
            $end = $data->end;
            $dept = $data->dept;
            $days = $data->days;
            $assign = $data->assign;
            $workday = $data->workday;
        }

        $this->app->loadConfig('project');
        $begin = $begin ? strtotime($begin) : time();
        $end = $end ? strtotime($end) : time() + (7 * 24 * 3600);
        $end += 24 * 3600;
        $beginWeekDay = date('w', $begin);
        $begin = date('Y-m-d', $begin);
        $end = date('Y-m-d', $end);

        if (empty($workday)) $workday = $this->config->project->defaultWorkhours;
        $diffDays = helper::diffDate($end, $begin);
        if ($days > $diffDays) $days = $diffDays;
        if (empty($days)) {
            $weekDay = $beginWeekDay;
            $days = $diffDays;
            for ($i = 0; $i < $diffDays; $i++, $weekDay++) {
                $weekDay = $weekDay % 7;
                if (($this->config->project->weekend == 2 and $weekDay == 6) or $weekDay == 0) $days--;
            }
        }

        $this->view->title = $this->lang->report->workload;
        $this->view->position[] = $this->lang->report->workload;

        $this->view->workload = $this->report->getWorkload($dept, $assign);
        $this->view->users = $this->loadModel('user')->getPairs('noletter|noclosed|nodeleted');
        $this->view->depts = $this->loadModel('dept')->getOptionMenu();
        $this->view->begin = $begin;
        $this->view->end = date('Y-m-d', strtotime($end) - 24 * 3600);
        $this->view->days = $days;
        $this->view->workday = $workday;
        $this->view->dept = $dept;
        $this->view->assign = $assign;
        $this->view->allHour = $days * $workday;
        $this->view->submenu = 'staff';
        $this->display();
    }

    /**
     * Send daily reminder mail.
     *
     * @access public
     * @return void
     */
    public function remind()
    {
        $bugs = $tasks = $todos = $testTasks = array();
        if ($this->config->report->dailyreminder->bug) $bugs = $this->report->getUserBugs();
        if ($this->config->report->dailyreminder->task) $tasks = $this->report->getUserTasks();
        if ($this->config->report->dailyreminder->todo) $todos = $this->report->getUserTodos();
        if ($this->config->report->dailyreminder->testTask) $testTasks = $this->report->getUserTestTasks();

        $reminder = array();

        $users = array_unique(array_merge(array_keys($bugs), array_keys($tasks), array_keys($todos), array_keys($testTasks)));
        if (!empty($users)) foreach ($users as $user) $reminder[$user] = new stdclass();

        if (!empty($bugs)) foreach ($bugs as $user => $bug) $reminder[$user]->bugs = $bug;
        if (!empty($tasks)) foreach ($tasks as $user => $task) $reminder[$user]->tasks = $task;
        if (!empty($todos)) foreach ($todos as $user => $todo) $reminder[$user]->todos = $todo;
        if (!empty($testTasks)) foreach ($testTasks as $user => $testTask) $reminder[$user]->testTasks = $testTask;

        $this->loadModel('mail');

        /* Check mail turnon.*/
        if (!$this->config->mail->turnon) {
            echo "You should turn on the Email feature first.\n";
            return false;
        }

        foreach ($reminder as $user => $mail) {
            /* Reset $this->output. */
            $this->clear();

            $mailTitle = $this->lang->report->mailTitle->begin;
            $mailTitle .= isset($mail->bugs) ? sprintf($this->lang->report->mailTitle->bug, count($mail->bugs)) : '';
            $mailTitle .= isset($mail->tasks) ? sprintf($this->lang->report->mailTitle->task, count($mail->tasks)) : '';
            $mailTitle .= isset($mail->todos) ? sprintf($this->lang->report->mailTitle->todo, count($mail->todos)) : '';
            $mailTitle .= isset($mail->testTasks) ? sprintf($this->lang->report->mailTitle->testTask, count($mail->testTasks)) : '';
            $mailTitle = rtrim($mailTitle, ',');

            /* Get email content and title.*/
            $this->view->mail = $mail;
            $this->view->mailTitle = $mailTitle;

            $oldViewType = $this->viewType;
            if ($oldViewType == 'json') $this->viewType = 'html';
            $mailContent = $this->parse('report', 'dailyreminder');
            $this->viewType == $oldViewType;

            /* Send email.*/
            echo date('Y-m-d H:i:s') . " sending to $user, ";
            $this->mail->send($user, $mailTitle, $mailContent, '', true);
            if ($this->mail->isError()) {
                echo "fail: \n";
                a($this->mail->getError());
            }
            echo "ok\n";
        }
    }


    /**
     * 项目总耗时报表.
     *
     * @param string $begin 开始时间]【例：20191104】
     * @param string $end 结束时间【例：20191110】
     * @param int $dept 部门ID(0为所有部门)
     * @param int $project 项目ID
     *
     * @access public
     * @return void
     */
    public function projectSummary($begin = 0, $end = 0, $dept = 0, $project = 0)
    {
        $begin = $begin ? date('Y-m-d', strtotime($begin)) : '';
        $end = $end ? date('Y-m-d', strtotime($end)) : '';

        $this->view->title = $this->lang->report->projectSummary;
        $this->view->position[] = $this->lang->report->projectSummary;

        $this->view->projects = array('' => '') + $this->loadModel('project')->getPairs();
        $this->view->depts = $this->loadModel('dept')->getOptionMenu();
        $this->view->projectSummary = $this->report->getProjectSummary($begin, $end, $project, $dept);
        $this->view->project = $project;
        $this->view->dept = $dept;
        $this->view->begin = $begin;
        $this->view->end = $end;
        $this->view->submenu = 'project';
        $this->display();
    }

    /**
     * 导出Excel(项目总耗时报表).
     *
     * @param string $begin 开始时间]【例：20191104】
     * @param string $end 结束时间【例：20191110】
     * @param int $dept 部门ID(0为所有部门)
     * @param int $project 项目ID
     *
     * @access public
     * @return void
     */
    public function exportProjectSummary($begin = 0, $end = 0, $dept = 0, $project = 0) {
        $begin = $begin ? date('Y-m-d', strtotime($begin)) : '';
        $end = $end ? date('Y-m-d', strtotime($end)) : '';
        $title = $this->lang->report->projectSummary;

        $projectSummary = $this->report->getProjectSummary($begin, $end, $dept, $project);

        $totalProjectTime = 0;

        $styleThinBlackBorderOutline = array(
            'borders' => array(
                'allborders' => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN,
                    'color' => array(
                        'rgb' => '000000'
                    )
                ),
            ),
        );
        $styleFont = array(
            'font' => array(
                'name' => 'Serif',
                'size' => 12,
                'bold' => FALSE,
                'italic' => FALSE,
                'underline' => PHPExcel_Style_Font::UNDERLINE_NONE,
                'strike' => FALSE,
                'color' => array(
                    'rgb' => '666666'
                )
            )
        );
        $styleBoldFont = array(
            'font' => array(
                'name' => 'Serif',
                'size' => 12,
                'bold' => TRUE,
                'italic' => FALSE,
                'underline' => PHPExcel_Style_Font::UNDERLINE_NONE,
                'strike' => FALSE,
                'color' => array(
                    'rgb' => '666666'
                )
            )
        );
        $objPHPExcel = new PHPExcel();
//        $objPHPExcel->getDefaultStyle()->applyFromArray($styleThinBlackBorderOutline);
//        $objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(25);
        $objPHPExcel->getDefaultStyle()->getFont()->setName('Serif');
        $objPHPExcel->getDefaultStyle()->getFont()->setSize(12);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
        $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);

        //Set properties 设置文件属性
        $objPHPExcel->getProperties()
            ->setCreator("张立强")
            ->setLastModifiedBy("张立强")
            ->setTitle("Office 2007 XLSX Test Document")
            ->setSubject("Office 2007 XLSX Test Document")
            ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
            ->setKeywords("office 2007 openxml php")
            ->setCategory("亚康万玮-研发中心报表");

        $time = "";
        if ($begin != 0 && $end != 0) {
            $time = "(" . $begin . '到' . $end . ")";
        }

        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', "亚康万玮——研发中心\n" . $time . "" . $title);
        $objPHPExcel->getActiveSheet()->mergeCells('A1:C1');
        $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(40);
        $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setWrapText(true);
        $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(16)->getColor()->setARGB(PHPExcel_Style_Color::COLOR_BLACK);
        $objPHPExcel->getActiveSheet()->getStyle('A1:C1')->applyFromArray($styleThinBlackBorderOutline);

        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A2', $this->lang->report->code)
            ->setCellValue('B2', $this->lang->report->projectName)
            ->setCellValue('C2', $this->lang->report->projectsTotal);

        $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(30);

        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(25);
        $objPHPExcel->getActiveSheet()->getStyle('A2')->getFont()->setBold(true)->setSize(14)->getColor()->setARGB(PHPExcel_Style_Color::COLOR_BLACK);

        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(40);
        $objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->setBold(true)->setSize(14)->getColor()->setARGB(PHPExcel_Style_Color::COLOR_BLACK);

        $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(15);
        $objPHPExcel->getActiveSheet()->getStyle('C2')->getFont()->setBold(true)->setSize(14)->getColor()->setARGB(PHPExcel_Style_Color::COLOR_BLACK);


        $objPHPExcel->getActiveSheet()->getStyle('A2')->applyFromArray($styleThinBlackBorderOutline);
        $objPHPExcel->getActiveSheet()->getStyle('A2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('B2')->applyFromArray($styleThinBlackBorderOutline);
        $objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('C2')->applyFromArray($styleThinBlackBorderOutline);
        $objPHPExcel->getActiveSheet()->getStyle('C2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
        $objPHPExcel->getActiveSheet()->getStyle('C2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

        $col = 3;
        foreach ($projectSummary as $key => $project) {
            $objPHPExcel->setActiveSheetIndex(0)
                ->setCellValue('A' . $col, $project->code)
                ->setCellValue('B' . $col, $project->name)
                ->setCellValue('C' . $col, $project->consumed);

            $totalProjectTime += $project->consumed;

            $objPHPExcel->getActiveSheet()->getStyle('A' . $col)->applyFromArray($styleThinBlackBorderOutline);
            $objPHPExcel->getActiveSheet()->getStyle('A' . $col)->applyFromArray($styleFont);
            $objPHPExcel->getActiveSheet()->getStyle('A' . $col)->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $objPHPExcel->getActiveSheet()->getStyle('B' . $col)->applyFromArray($styleThinBlackBorderOutline);
            $objPHPExcel->getActiveSheet()->getStyle('B' . $col)->applyFromArray($styleFont);
            $objPHPExcel->getActiveSheet()->getStyle('B' . $col)->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

            $objPHPExcel->getActiveSheet()->getStyle('C' . $col)->applyFromArray($styleThinBlackBorderOutline);
            $objPHPExcel->getActiveSheet()->getStyle('C' . $col)->applyFromArray($styleFont);
            $objPHPExcel->getActiveSheet()->getStyle('C' . $col)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
            $objPHPExcel->getActiveSheet()->getStyle('C' . $col)->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $objPHPExcel->getActiveSheet()->getRowDimension($col)->setRowHeight(20);

            $col++;
        }
        $interval = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
        foreach ($interval as $key) {
            $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + $key))->applyFromArray($styleThinBlackBorderOutline);
            $objPHPExcel->getActiveSheet()->getStyle('B' . ($col + $key))->applyFromArray($styleThinBlackBorderOutline);
            $objPHPExcel->getActiveSheet()->getStyle('C' . ($col + $key))->applyFromArray($styleThinBlackBorderOutline);
            $objPHPExcel->getActiveSheet()->getRowDimension($col + $key)->setRowHeight(20);
            if ($key == 9) {
                $objPHPExcel->setActiveSheetIndex(0)
                    ->setCellValue('A' . ($col + $key),'合计')
                    ->setCellValue('C' . ($col + $key), $totalProjectTime);
                $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + $key))->applyFromArray($styleBoldFont);
                $objPHPExcel->getActiveSheet()->getStyle('C' . ($col + $key))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
            }
        }
        $rows = [10,11,12,13,14,15];
        $objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A' . ($col + $rows[0]), '研发一部经理审批签字：')
            ->setCellValue('A' . ($col + $rows[1]), '研发二部经理审批签字：')
            ->setCellValue('A' . ($col + $rows[2]), '研发三部经理审批签字：')
            ->setCellValue('A' . ($col + $rows[3]), '研发四部经理审批签字：')
            ->setCellValue('A' . ($col + $rows[sizeof($rows) - 2]), 'CEO审批签字：')
            ->setCellValue('A' . ($col + $rows[sizeof($rows) - 1]), '财务部审批签字：');

        foreach ($rows as $key => $index) {
            $objPHPExcel->getActiveSheet()->getRowDimension($col + $rows[$key])->setRowHeight(30);
            $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + $rows[$key]))->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            $objPHPExcel->getActiveSheet()->mergeCells('A' . ($col + $rows[$key]) . ':C' . ($col + $rows[$key]));
            $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + $rows[$key]) . ':C' . ($col + $rows[$key]))->applyFromArray($styleThinBlackBorderOutline);
        }
//        $objPHPExcel->getActiveSheet()->getRowDimension($col + $rows[0])->setRowHeight(30);
//        $objPHPExcel->getActiveSheet()->getRowDimension($col + $rows[1])->setRowHeight(30);
//        $objPHPExcel->getActiveSheet()->getRowDimension($col + $rows[2])->setRowHeight(30);
//        $objPHPExcel->getActiveSheet()->getRowDimension($col + $rows[3])->setRowHeight(30);
//        $objPHPExcel->getActiveSheet()->getRowDimension($col + $rows[sizeof($rows) - 2])->setRowHeight(30);
//        $objPHPExcel->getActiveSheet()->getRowDimension($col + $rows[sizeof($rows) - 1])->setRowHeight(30);
//
//        $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + $rows[0]))->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
//        $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + $rows[1]))->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
//        $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + $rows[2]))->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
//        $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + $rows[3]))->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
//        $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + $rows[sizeof($rows) - 2]))->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
//        $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + $rows[sizeof($rows) - 1]))->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
//
//        $objPHPExcel->getActiveSheet()->mergeCells('A' . ($col + $rows[0]) . ':C' . ($col + $rows[0]));
//        $objPHPExcel->getActiveSheet()->mergeCells('A' . ($col + $rows[1]) . ':C' . ($col + $rows[1]));
//        $objPHPExcel->getActiveSheet()->mergeCells('A' . ($col + $rows[2]) . ':C' . ($col + $rows[2]));
//        $objPHPExcel->getActiveSheet()->mergeCells('A' . ($col + $rows[3]) . ':C' . ($col + $rows[3]));
//        $objPHPExcel->getActiveSheet()->mergeCells('A' . ($col + $rows[sizeof($rows) - 2]) . ':C' . ($col + $rows[sizeof($rows) - 2]));
//        $objPHPExcel->getActiveSheet()->mergeCells('A' . ($col + $rows[sizeof($rows) - 1]) . ':C' . ($col + $rows[sizeof($rows) - 1]));
//
//        $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + $rows[0]) . ':C' . ($col + $rows[0]))->applyFromArray($styleThinBlackBorderOutline);
//        $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + $rows[1]) . ':C' . ($col + $rows[1]))->applyFromArray($styleThinBlackBorderOutline);
//        $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + $rows[2]) . ':C' . ($col + $rows[2]))->applyFromArray($styleThinBlackBorderOutline);
//        $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + $rows[3]) . ':C' . ($col + $rows[3]))->applyFromArray($styleThinBlackBorderOutline);
//        $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + $rows[sizeof($rows) - 2]) . ':C' . ($col + $rows[sizeof($rows) - 2]))->applyFromArray($styleThinBlackBorderOutline);
//        $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + $rows[sizeof($rows) - 1]) . ':C' . ($col + $rows[sizeof($rows) - 1]))->applyFromArray($styleThinBlackBorderOutline);

        $objPHPExcel->getActiveSheet()->setTitle("项目总耗时");
        $objPHPExcel->setActiveSheetIndex(0);
        $filename = urlencode($title) . '_' . date('Y-m-dHis');

        header("Content-Type:application/vnd.ms-excel");
        header('Content-Disposition: attachment;filename="' . $filename . '.xlsx"');
        header('Cache-Control: max-age=0');
        header("Pragma:no-cache");
        header("Expires:0");

        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
        $objWriter->save('php://output');
        exit;
    }

    /**
     * 项目人员分布表.
     *
     * @param string $begin 开始时间]【例：20191104】
     * @param string $end 结束时间【例：20191110】
     * @param int $dept 部门ID(0为所有部门)
     * @param int $project 项目ID
     *
     * @access public
     * @return void
     */
    public function projectUserSummary($begin = 0, $end = 0, $dept = 0, $project = 0)
    {
        $begin = $begin ? date('Y-m-d', strtotime($begin)) : '';
        $end = $end ? date('Y-m-d', strtotime($end)) : '';

        $this->view->title = $this->lang->report->projectUserSummary;
        $this->view->position[] = $this->lang->report->projectUserSummary;

        $this->view->projects = array('' => '') + $this->loadModel('project')->getPairs();
        $this->view->depts = $this->loadModel('dept')->getOptionMenu();
        $this->view->projectUserSummary = $this->report->getProjectUserSummary($begin, $end, $dept, $project);
        $this->view->project = $project;
        $this->view->dept = $dept;
        $this->view->begin = $begin;
        $this->view->end = $end;
        $this->view->submenu = 'project';
        $this->display();
    }

    /**
     * 导出Excel（项目人员分布表.）
     *
     * @param string $begin 开始时间]【例：20191104】
     * @param string $end 结束时间【例：20191110】
     * @param int $dept 部门ID(0为所有部门)
     * @param int $project 项目ID
     *
     * @access public
     * @return void
     */
    public function exportProjectUserSummary($begin = 0, $end = 0, $dept = 0, $project = 0) {
        $begin = $begin ? date('Y-m-d', strtotime($begin)) : '';
        $end = $end ? date('Y-m-d', strtotime($end)) : '';
        $title = $this->lang->report->projectUserSummary;

        $depts = $this->loadModel('dept')->getOptionMenu();

        $styleThinBlackBorderOutline = array(
            'borders' => array(
                'allborders' => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN,
                    'color' => array(
                        'rgb' => '000000'
                    )
                ),
            ),
        );
        $styleFont = array(
            'font' => array(
                'name' => 'Serif',
                'size' => 12,
                'bold' => FALSE,
                'italic' => FALSE,
                'underline' => PHPExcel_Style_Font::UNDERLINE_NONE,
                'strike' => FALSE,
                'color' => array(
                    'rgb' => '666666'
                )
            )
        );

        $objPHPExcel = new PHPExcel();

        $startRow = 3;
        if ($dept == 0) {
            $index = 0;
            foreach ($depts as $key => $dept) {
                if ($key != 0) {
                    $projectUserSummary = $this->report->getProjectUserSummary($begin, $end, $key, $project);
                    $objPHPExcel = $this->report->writeProjectUserSummary($objPHPExcel, $index, $startRow, $projectUserSummary, mb_substr($dept, 1, 5, 'utf-8'), $begin, $end, $styleThinBlackBorderOutline, $styleFont);
                    $objPHPExcel->setActiveSheetIndex($index);
                    $index++;
                }
            }
            $objPHPExcel->setActiveSheetIndex(0);
            $objPHPExcel->removeSheetByIndex($index++);
        }
        if ($dept != 0) {
            $deptArray = array();
            foreach ($depts as $key => $value) {
                $deptArray[$key] = mb_substr($value, 1, 5, 'utf-8');
            }
            $projectUserSummary = $this->report->getProjectUserSummary($begin, $end, $dept, $project);
            $objPHPExcel = $this->report->writeProjectUserSummary($objPHPExcel, 0, $startRow, $projectUserSummary, $deptArray[$dept], $begin, $end, $styleThinBlackBorderOutline, $styleFont);
            $objPHPExcel->setActiveSheetIndex(0);
            $objPHPExcel->removeSheetByIndex(1);
        }
        /*
        //        $projectUserSummary = $this->report->getProjectUserSummary($begin, $end, $dept, $project);
                //Set properties 设置文件属性
                $objPHPExcel->getProperties()
                    ->setCreator("张立强")
                    ->setLastModifiedBy("张立强")
                    ->setTitle("Office 2007 XLSX Test Document")
                    ->setSubject("Office 2007 XLSX Test Document")
                    ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
                    ->setKeywords("office 2007 openxml php")
                    ->setCategory("亚康万玮-研发中心报表");

                $time = "";
                if ($begin != 0 && $end != 0) {
                    $time = "(" . $begin . '到' . $end . ")";
                }

                $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(18);
                $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
                $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(12);
                $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(14);
                $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(14);

                $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', "亚康万玮——研发中心\n" . $time . "" . $title);
        //合并列
                $objPHPExcel->getActiveSheet()->mergeCells('A1:E1');
                $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(35);
                $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setWrapText(true);
                $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(16)->getColor()->setARGB(PHPExcel_Style_Color::COLOR_BLACK);
                $objPHPExcel->getActiveSheet()->getStyle('A1:E1')->applyFromArray($styleThinBlackBorderOutline);

        //表格标题赋值
                $objPHPExcel->setActiveSheetIndex(0)
                    ->setCellValue('A2', $this->lang->report->code)
                    ->setCellValue('B2', $this->lang->report->projectName)
                    ->setCellValue('C2', $this->lang->report->user)
                    ->setCellValue('D2', $this->lang->report->myConsumed)
                    ->setCellValue('E2', $this->lang->report->projectsTotal);
        //设置行高
                $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(30);
        //设置边框
                $objPHPExcel->getActiveSheet()->getStyle('A2')->applyFromArray($styleThinBlackBorderOutline);
                $objPHPExcel->getActiveSheet()->getStyle('B2')->applyFromArray($styleThinBlackBorderOutline);
                $objPHPExcel->getActiveSheet()->getStyle('C2')->applyFromArray($styleThinBlackBorderOutline);
                $objPHPExcel->getActiveSheet()->getStyle('D2')->applyFromArray($styleThinBlackBorderOutline);
                $objPHPExcel->getActiveSheet()->getStyle('E2')->applyFromArray($styleThinBlackBorderOutline);
        //设置表格字体
                $objPHPExcel->getActiveSheet()->getStyle('A2')->getFont()->setBold(true)->setSize(14)->getColor()->setARGB(PHPExcel_Style_Color::COLOR_BLACK);
                $objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->setBold(true)->setSize(14)->getColor()->setARGB(PHPExcel_Style_Color::COLOR_BLACK);
                $objPHPExcel->getActiveSheet()->getStyle('C2')->getFont()->setBold(true)->setSize(14)->getColor()->setARGB(PHPExcel_Style_Color::COLOR_BLACK);
                $objPHPExcel->getActiveSheet()->getStyle('D2')->getFont()->setBold(true)->setSize(14)->getColor()->setARGB(PHPExcel_Style_Color::COLOR_BLACK);
                $objPHPExcel->getActiveSheet()->getStyle('E2')->getFont()->setBold(true)->setSize(14)->getColor()->setARGB(PHPExcel_Style_Color::COLOR_BLACK);
        //设置字体纵向对齐方式
                $objPHPExcel->getActiveSheet()->getStyle('A2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $objPHPExcel->getActiveSheet()->getStyle('C2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $objPHPExcel->getActiveSheet()->getStyle('D2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $objPHPExcel->getActiveSheet()->getStyle('E2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $col = 3;
                foreach ($projectUserSummary as $id => $value) {
                    $i = 1;
                    foreach ($value['user'] as $finishedBy => $user) {
                        if ($i == 1) {
                            $objPHPExcel->setActiveSheetIndex(0)
                                ->setCellValue('A' . $col, $value['code'])
                                ->setCellValue('B' . $col, $value['name'])
                                ->setCellValue('C' . $col, $user["finishedBy"])
                                ->setCellValue('D' . $col, $user['consumed'])
                                ->setCellValue('E' . $col, $value['consumed']);

                            $objPHPExcel->getActiveSheet()->mergeCells('A' . $col . ':A' . (count($value['user']) + $col - $i));
                            $objPHPExcel->getActiveSheet()->getStyle('A' . $col . ':A' . (count($value['user']) + $col - $i))->applyFromArray($styleFont);
                            $objPHPExcel->getActiveSheet()->getStyle('A' . $col . ':A' . (count($value['user']) + $col - $i))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

                            $objPHPExcel->getActiveSheet()->mergeCells('B' . $col . ':B' . (count($value['user']) + $col - $i));
                            $objPHPExcel->getActiveSheet()->getStyle('B' . $col . ':B' . (count($value['user']) + $col - $i))->applyFromArray($styleFont);
                            $objPHPExcel->getActiveSheet()->getStyle('B' . $col . ':B' . (count($value['user']) + $col - $i))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

                            $objPHPExcel->getActiveSheet()->mergeCells('E' . $col . ':E' . (count($value['user']) + $col - $i));
                            $objPHPExcel->getActiveSheet()->getStyle('E' . $col . ':E' . (count($value['user']) + $col - $i))->applyFromArray($styleFont);
                            $objPHPExcel->getActiveSheet()->getStyle('E' . $col . ':E' . (count($value['user']) + $col - $i))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

                            $objPHPExcel->getActiveSheet()->getStyle('A' . $col)->applyFromArray($styleThinBlackBorderOutline);
                            $objPHPExcel->getActiveSheet()->getStyle('B' . $col)->applyFromArray($styleThinBlackBorderOutline);
                            $objPHPExcel->getActiveSheet()->getStyle('C' . $col)->applyFromArray($styleThinBlackBorderOutline);
                            $objPHPExcel->getActiveSheet()->getStyle('C' . $col)->applyFromArray($styleFont);
                            $objPHPExcel->getActiveSheet()->getStyle('C' . $col)->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                            $objPHPExcel->getActiveSheet()->getStyle('D' . $col)->applyFromArray($styleThinBlackBorderOutline);
                            $objPHPExcel->getActiveSheet()->getStyle('D' . $col)->applyFromArray($styleFont);
                            $objPHPExcel->getActiveSheet()->getStyle('D' . $col)->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                            $objPHPExcel->getActiveSheet()->getStyle('D' . $col)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
                            $objPHPExcel->getActiveSheet()->getStyle('E' . $col)->applyFromArray($styleThinBlackBorderOutline);
                            $objPHPExcel->getActiveSheet()->getStyle('E' . $col)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

                            $objPHPExcel->getActiveSheet()->getStyle('A' . $col . ':A' . (count($value['user']) + $col - $i))->applyFromArray($styleThinBlackBorderOutline);
                            $objPHPExcel->getActiveSheet()->getStyle('B' . $col . ':B' . (count($value['user']) + $col - $i))->applyFromArray($styleThinBlackBorderOutline);
                            $objPHPExcel->getActiveSheet()->getStyle('E' . $col . ':E' . (count($value['user']) + $col - $i))->applyFromArray($styleThinBlackBorderOutline);
                        } else {
                            $objPHPExcel->setActiveSheetIndex(0)
                                ->setCellValue('C' . $col, $user["finishedBy"])
                                ->setCellValue('D' . $col, $user["consumed"]);

                            $objPHPExcel->getActiveSheet()->getStyle('C' . $col)->applyFromArray($styleFont);
                            $objPHPExcel->getActiveSheet()->getStyle('C' . $col)->applyFromArray($styleThinBlackBorderOutline);
                            $objPHPExcel->getActiveSheet()->getStyle('C' . $col)->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

                            $objPHPExcel->getActiveSheet()->getStyle('D' . $col)->applyFromArray($styleFont);
                            $objPHPExcel->getActiveSheet()->getStyle('D' . $col)->applyFromArray($styleThinBlackBorderOutline);
                            $objPHPExcel->getActiveSheet()->getStyle('D' . $col)->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                            $objPHPExcel->getActiveSheet()->getStyle('D' . $col)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);

                        }
                        $objPHPExcel->getActiveSheet()->getRowDimension($col)->setRowHeight(20);
                        $i++;
                        $col++;
                    }
                }

                $interval = array(0, 1, 2, 3, 4, 5);
                foreach ($interval as $key) {
                    $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + $key))->applyFromArray($styleThinBlackBorderOutline);
                    $objPHPExcel->getActiveSheet()->getStyle('B' . ($col + $key))->applyFromArray($styleThinBlackBorderOutline);
                    $objPHPExcel->getActiveSheet()->getStyle('C' . ($col + $key))->applyFromArray($styleThinBlackBorderOutline);
                    $objPHPExcel->getActiveSheet()->getStyle('D' . ($col + $key))->applyFromArray($styleThinBlackBorderOutline);
                    $objPHPExcel->getActiveSheet()->getStyle('E' . ($col + $key))->applyFromArray($styleThinBlackBorderOutline);
                    $objPHPExcel->getActiveSheet()->getRowDimension($col + $key)->setRowHeight(20);
                }
                $objPHPExcel->setActiveSheetIndex(0)
                    ->setCellValue('A' . ($col + 6), '研发一部经理审批签字：')
                    ->setCellValue('A' . ($col + 7), '研发二部经理审批签字：')
                    ->setCellValue('A' . ($col + 8), 'CEO审批签字：')
                    ->setCellValue('A' . ($col + 9), '财务部审批签字：');

                $objPHPExcel->getActiveSheet()->getRowDimension($col + 6)->setRowHeight(30);
                $objPHPExcel->getActiveSheet()->getRowDimension($col + 7)->setRowHeight(30);
                $objPHPExcel->getActiveSheet()->getRowDimension($col + 8)->setRowHeight(30);
                $objPHPExcel->getActiveSheet()->getRowDimension($col + 9)->setRowHeight(30);

                $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + 6))->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + 7))->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + 8))->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
                $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + 9))->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

                $objPHPExcel->getActiveSheet()->mergeCells('A' . ($col + 6) . ':E' . ($col + 6));
                $objPHPExcel->getActiveSheet()->mergeCells('A' . ($col + 7) . ':E' . ($col + 7));
                $objPHPExcel->getActiveSheet()->mergeCells('A' . ($col + 8) . ':E' . ($col + 8));
                $objPHPExcel->getActiveSheet()->mergeCells('A' . ($col + 9) . ':E' . ($col + 9));

                $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + 6) . ':E' . ($col + 6))->applyFromArray($styleThinBlackBorderOutline);
                $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + 7) . ':E' . ($col + 7))->applyFromArray($styleThinBlackBorderOutline);
                $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + 8) . ':E' . ($col + 8))->applyFromArray($styleThinBlackBorderOutline);
                $objPHPExcel->getActiveSheet()->getStyle('A' . ($col + 9) . ':E' . ($col + 9))->applyFromArray($styleThinBlackBorderOutline);

                $objPHPExcel->getActiveSheet()->setTitle("项目人员分布");
                $objPHPExcel->setActiveSheetIndex(0);
        */

        $filename = urlencode($title) . '_' . date('Y-m-dHis');
        header("Content-Type:application/vnd.ms-excel");
        header('Content-Disposition: attachment;filename="' . $filename . '.xlsx"');
        header('Cache-Control: max-age=0');
        header("Pragma:no-cache");
        header("Expires:0");
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
        $objWriter->save('php://output');
        exit;
    }

    /**
     * 任务汇总表.
     *
     * @param string $begin 开始时间]【例：20191104】
     * @param string $end 结束时间【例：20191110】
     * @param string $user 用户名【例：zhangsan】
     * @param int $dept 部门ID(0为所有部门)
     * @param int $project 项目ID
     *
     * @access public
     * @return void
     */
    public function taskSummary($begin = '', $end = '', $user = 0, $dept = 0, $project = 0)
    {
        if ($_POST) {
            $data = fixer::input('post')->get();
            $begin = $data->begin;
            $end = $data->end;
            $dept = $data->dept;
            $user = $data->user;
        }

        $this->app->loadConfig('project');
        $begin = $begin ? strtotime($begin) : time() - (7 * 24 * 3600);
        $end = $end ? strtotime($end) : time();
        $begin = date('Y-m-d', $begin);
        $end = date('Y-m-d', $end);

        $this->view->title = $this->lang->report->taskSummary;
        $this->view->position[] = $this->lang->report->taskSummary;

        $this->view->taskSummary = $this->report->getTaskSummary($begin, $end, $user, $dept, $project);
        $this->view->projects = array('' => '') + $this->loadModel('project')->getPairs();
        $this->view->depts = $this->loadModel('dept')->getOptionMenu();
        $this->view->users = $this->loadModel('user')->getPairs('noletter|noclosed|nodeleted');
        if ($dept) {
            $this->view->users = array('' => '') + $this->loadModel('dept')->getDeptUserPairs($dept);
        }
        $this->view->begin = $begin;
        $this->view->end = date('Y-m-d', strtotime($end));
        $this->view->project = $project;
        $this->view->dept = $dept;
        $this->view->user = $user;
        $this->view->submenu = 'staff';
        $this->display();
    }

    /**
     * 导出Excel(任务汇总表).
     *
     * @param string $begin 开始时间]【例：20191104】
     * @param string $end 结束时间【例：20191110】
     * @param string $user 用户名【例：zhangsan】
     * @param int $dept 部门ID(0为所有部门)
     * @param int $project 项目ID
     *
     * @access public
     * @return void
     */
    public function exportTaskSummary($begin = '', $end = '', $user = 0, $dept = 0, $project = 0)
    {
        $this->app->loadConfig('project');
        $begin = $begin ? strtotime($begin) : time() - (7 * 24 * 3600);
        $end = $end ? strtotime($end) : time();
        $begin = date('Y-m-d', $begin);
        $end = date('Y-m-d', $end);

        $title = $this->lang->report->taskSummary;

        $styleThinBlackBorderOutline = array(
            'borders' => array(
                'allborders' => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN,
                    'color' => array(
                        'rgb' => '000000'
                    )
                ),
            ),
        );
        $styleFont = array(
            'font' => array(
                'name' => 'Serif',
                'size' => 12,
                'bold' => FALSE,
                'italic' => FALSE,
                'underline' => PHPExcel_Style_Font::UNDERLINE_NONE,
                'strike' => FALSE,
                'color' => array(
                    'rgb' => '666666'
                )
            )
        );
        $taskSummary = $this->report->getTaskSummary($begin, $end, $user, $dept, $project);
//        $users = $this->loadModel('user')->getPairs('noletter|noclosed|nodeleted');
        $depts = $this->loadModel('dept')->getOptionMenu();

        $taskSummarys = array();

        if (empty($taskSummarys)) {
            $taskSummarys = $taskSummary;
        }

        $objPHPExcel = new PHPExcel();

        $startRow = 3;
        if ($dept == 0) {
            $index = 0;
            foreach ($depts as $key => $dept) {
                if ($key != 0) {
                    $taskSummary = $this->report->getTaskSummary($begin, $end, $user, $key, $project);
                    $objPHPExcel = $this->report->writeTaskSummaryExcel($objPHPExcel, $index, $startRow, $taskSummary, mb_substr($dept, 1, 5, 'utf-8'), $begin, $end, $styleThinBlackBorderOutline, $styleFont);
                    $objPHPExcel->setActiveSheetIndex($index);
                    $index++;
                }
            }
            $objPHPExcel->setActiveSheetIndex(0);
            $objPHPExcel->removeSheetByIndex($index++);
        }
        if ($dept != 0) {
            $deptArray = array();
            foreach ($depts as $key => $value) {
                $deptArray[$key] = mb_substr($value, 1, 5, 'utf-8');
            }
            $index = 0;
            $taskSummarys = $this->report->getTaskSummary($begin, $end, $user, $dept, $project);
            $objPHPExcel = $this->report->writeTaskSummaryExcel($objPHPExcel, $index, $startRow, $taskSummarys, $deptArray[$dept], $begin, $end, $styleThinBlackBorderOutline, $styleFont);
            $objPHPExcel->setActiveSheetIndex(0);
        }

        $filename = urlencode($title) . '_' . date('Y-m-dHis');

        header("Content-Type:application/vnd.ms-excel");
        header('Content-Disposition: attachment;filename="' . $filename . '.xlsx"');
        header('Cache-Control: max-age=0');
        header("Pragma:no-cache");
        header("Expires:0");
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
        $objWriter->save('php://output');
        exit;
    }

    /**
     * 任务跟踪汇总表.
     *
     * @param string $begin 开始时间]【例：20191104】
     * @param string $end 结束时间【例：20191110】
     * @param string $user 用户名【例：zhangsan】
     * @param int $dept 部门ID(0为所有部门)
     * @param int $project 项目ID
     *
     * @access public
     * @return void
     */
    public function taskTrackingSummary($begin = '', $end = '', $user = 0, $dept = 0, $project = 0)
    {
        if ($_POST) {
            $data = fixer::input('post')->get();
            $begin = $data->begin;
            $end = $data->end;
            $dept = $data->dept;
            $user = $data->user;
        }

        $this->app->loadConfig('project');
        $begin = $begin ? strtotime($begin) : time() - (7 * 24 * 3600);
        $end = $end ? strtotime($end) : time();
        $begin = date('Y-m-d', $begin);
        $end = date('Y-m-d', $end);

        $this->view->title = $this->lang->report->taskTrackingSummary;
        $this->view->position[] = $this->lang->report->taskTrackingSummary;

        $this->view->taskStatus = $this->lang->task->statusList;
        $this->view->taskPri = $this->lang->task->priList;
        $this->view->taskType = $this->lang->task->typeList;
        $this->view->taskSummary = $this->report->getTaskTrackingSummary($begin, $end, $user, $dept, $project);
        $this->view->projects = array('' => '') + $this->loadModel('project')->getPairs();
        $this->view->depts = $this->loadModel('dept')->getOptionMenu();
        $this->view->users = $this->loadModel('user')->getPairs('noletter|noclosed|nodeleted');
        if ($dept) {
            $this->view->users = array('' => '') + $this->loadModel('dept')->getDeptUserPairs($dept);
        }
        $this->view->begin = $begin;
        $this->view->end = date('Y-m-d', strtotime($end));
        $this->view->project = $project;
        $this->view->dept = $dept;
        $this->view->user = $user;
        $this->view->submenu = 'staff';
        $this->display();
    }

    /**
     * 导出Excel(任务汇总表).
     *
     * @param string $begin 开始时间]【例：20191104】
     * @param string $end 结束时间【例：20191110】
     * @param string $user 用户名【例：zhangsan】
     * @param int $dept 部门ID(0为所有部门)
     * @param int $project 项目ID
     *
     * @access public
     * @return void
     */
    public function exportTaskTrackingSummary($begin = '', $end = '', $user = 0, $dept = 0, $project = 0)
    {
        $this->app->loadConfig('project');
        $begin = $begin ? strtotime($begin) : time() - (7 * 24 * 3600);
        $end = $end ? strtotime($end) : time();
        $begin = date('Y-m-d', $begin);
        $end = date('Y-m-d', $end);

        $title = $this->lang->report->taskTrackingSummary;

        $styleThinBlackBorderOutline = array(
            'borders' => array(
                'allborders' => array(
                    'style' => PHPExcel_Style_Border::BORDER_THIN,
                    'color' => array(
                        'rgb' => '000000'
                    )
                ),
            ),
        );
        $styleFont = array(
            'font' => array(
                'name' => 'Serif',
                'size' => 12,
                'bold' => FALSE,
                'italic' => FALSE,
                'underline' => PHPExcel_Style_Font::UNDERLINE_NONE,
                'strike' => FALSE,
                'color' => array(
                    'rgb' => '666666'
                )
            )
        );
        $taskTrackingSummary = $this->report->getTaskTrackingSummary($begin, $end, $user, $dept, $project);
//        $users = $this->loadModel('user')->getPairs('noletter|noclosed|nodeleted');
        $depts = $this->loadModel('dept')->getOptionMenu();
        $taskPri = $this->lang->task->priList;
        $taskType = $this->lang->task->typeList;
        $taskStatus = $this->lang->task->statusList;

        $taskTrackingSummary = array();

        if (empty($taskTrackingSummary)) {
            $taskTrackingSummary = $taskTrackingSummary;
        }

        $objPHPExcel = new PHPExcel();

        $startRow = 3;
        if ($dept == 0) {
            $index = 0;
            foreach ($depts as $key => $dept) {
                if ($key != 0) {
                    $taskTrackingSummary = $this->report->getTaskTrackingSummary($begin, $end, $user, $key, $project);
                    $objPHPExcel = $this->report->writeTaskTrackingSummaryExcel($objPHPExcel, $index, $startRow, $taskTrackingSummary, mb_substr($dept, 1, 5, 'utf-8'), $begin, $end, $styleThinBlackBorderOutline, $styleFont,$taskPri,$taskType,$taskStatus);
                    $objPHPExcel->setActiveSheetIndex($index);
                    $index++;
                }
            }
            $objPHPExcel->setActiveSheetIndex(0);
            $objPHPExcel->removeSheetByIndex($index++);
        }
        if ($dept != 0) {
            $deptArray = array();
            foreach ($depts as $key => $value) {
                $deptArray[$key] = mb_substr($value, 1, 5, 'utf-8');
            }
            $index = 0;
            $taskTrackingSummary = $this->report->getTaskTrackingSummary($begin, $end, $user, $dept, $project);
            $objPHPExcel = $this->report->writeTaskTrackingSummaryExcel($objPHPExcel, $index, $startRow, $taskTrackingSummary, $deptArray[$dept], $begin, $end, $styleThinBlackBorderOutline, $styleFont,$taskPri,$taskType,$taskStatus);
            $objPHPExcel->setActiveSheetIndex(0);
        }

        $filename = urlencode($title) . '_' . date('Y-m-dHis');

        header("Content-Type:application/vnd.ms-excel");
        header('Content-Disposition: attachment;filename="' . $filename . '.xlsx"');
        header('Cache-Control: max-age=0');
        header("Pragma:no-cache");
        header("Expires:0");
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
        $objWriter->save('php://output');
        exit;
    }

}
